package com.appwoo.txtws.util;

import android.app.Dialog;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.graphics.Bitmap;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.GridView;
import android.widget.ImageView;
import com.appwoo.txtws.bean.AutoSoftInfo;
import com.appwoo.txtws.component.Logger;

public class DialogDragGrid extends GridView
{
  Animation AtoB;
  Animation BtoA;
  Animation DelDone;
  private Dialog dialog;
  private WindowManager.LayoutParams dialogLP;
  private int dragPosition;
  private int dropPosition;
  boolean flag = false;
  ViewGroup fromView;
  boolean isCountXY = false;
  private G_ItemChangeListener itemListener;
  private ImageView iv_drag;
  private int mLastX;
  private int mLastY;
  int moveNum;
  private int numColumns;
  private G_PageListener pageListener;
  private int parentid = 0;
  int stopCount = 0;
  private WindowManager windowManager;
  private WindowManager.LayoutParams windowParams;
  private int xtox;
  private int ytoy;

  public DialogDragGrid(Context paramContext, int paramInt1, Dialog paramDialog, int paramInt2)
  {
    super(paramContext);
    this.numColumns = paramInt1;
    this.dialog = paramDialog;
    this.dialogLP = paramDialog.getWindow().getAttributes();
    this.parentid = paramInt2;
  }

  public DialogDragGrid(Context paramContext, AttributeSet paramAttributeSet)
  {
    super(paramContext, paramAttributeSet);
  }

  private void onDrag(int paramInt1, int paramInt2)
  {
    if (this.iv_drag != null)
    {
      this.windowParams.alpha = 0.8F;
      this.windowParams.x = (paramInt1 - this.mLastX - this.xtox + this.fromView.getLeft() - this.moveNum * DialogConfigure.screenWidth);
      this.windowParams.y = (paramInt2 - this.mLastY - this.ytoy + this.fromView.getTop() + (int)(40.0F * DialogConfigure.screenDensity));
      this.windowManager.updateViewLayout(this.iv_drag, this.windowParams);
    }
    Logger.i("xy", "x:" + paramInt1 + " y:" + paramInt2 + " width:" + this.dialogLP.width + " height:" + this.dialogLP.height);
    if ((paramInt1 < 0) || (paramInt2 < 0) || (paramInt1 > this.dialogLP.width) || (paramInt2 > this.dialogLP.height))
    {
      com.appwoo.txtws.activity.MainActivity.dragDialogPosition = this.dragPosition;
      stopDrag();
      this.AtoB = getDownAnimation(0.0F, 0.0F);
      this.fromView.startAnimation(this.AtoB);
      this.AtoB.setAnimationListener(new Animation.AnimationListener()
      {
        public void onAnimationEnd(Animation paramAnonymousAnimation)
        {
        }

        public void onAnimationRepeat(Animation paramAnonymousAnimation)
        {
        }

        public void onAnimationStart(Animation paramAnonymousAnimation)
        {
        }
      });
      this.dialog.cancel();
    }
    if (this.moveNum > 0)
      if (((paramInt1 >= (1 + this.moveNum) * DialogConfigure.screenWidth - 20.0F * DialogConfigure.screenDensity) || (paramInt1 <= this.moveNum * DialogConfigure.screenWidth)) && (!DialogConfigure.isChangingPage))
      {
        this.stopCount = (1 + this.stopCount);
        if (this.stopCount > 5)
        {
          this.stopCount = 0;
          if ((paramInt1 < (1 + this.moveNum) * DialogConfigure.screenWidth - 20.0F * DialogConfigure.screenDensity) || (DialogConfigure.curentPage >= -1 + DialogConfigure.countPages))
            break label380;
          DialogConfigure.isChangingPage = true;
          this.moveNum = (1 + this.moveNum);
        }
      }
    label380: 
    do
      while (true)
      {
        return;
        this.stopCount = 0;
        break;
        if ((paramInt1 <= this.moveNum * DialogConfigure.screenWidth) && (DialogConfigure.curentPage > 0))
        {
          DialogConfigure.isChangingPage = true;
          this.moveNum = (-1 + this.moveNum);
          return;
          Logger.i("draggrid", "x:" + paramInt1 + " movenum:" + this.moveNum + "  screenwidth:" + DialogConfigure.screenWidth + " d:" + DialogConfigure.screenDensity);
          if (((paramInt1 >= (1 + this.moveNum) * DialogConfigure.screenWidth - 20.0F * DialogConfigure.screenDensity) || (paramInt1 <= this.moveNum * DialogConfigure.screenWidth)) && (!DialogConfigure.isChangingPage));
          for (this.stopCount = (1 + this.stopCount); this.stopCount > 5; this.stopCount = 0)
          {
            this.stopCount = 0;
            if ((paramInt1 < (1 + this.moveNum) * DialogConfigure.screenWidth - 20.0F * DialogConfigure.screenDensity) || (DialogConfigure.curentPage >= -1 + DialogConfigure.countPages))
              break label591;
            DialogConfigure.isChangingPage = true;
            this.moveNum = (1 + this.moveNum);
            return;
          }
        }
      }
    while ((paramInt1 > this.moveNum * DialogConfigure.screenWidth) || (DialogConfigure.curentPage <= 0));
    label591: DialogConfigure.isChangingPage = true;
    this.moveNum = (-1 + this.moveNum);
  }

  private void onDrop(int paramInt1, int paramInt2)
  {
    this.fromView.setDrawingCacheBackgroundColor(0);
    DialogConfigure.isMove = false;
    int i = pointToPosition(paramInt1 - this.moveNum * DialogConfigure.screenWidth, paramInt2);
    if (i != -1)
      this.dropPosition = i;
    if (this.moveNum != 0)
    {
      this.itemListener.change(this.dragPosition, this.dropPosition, this.moveNum);
      this.moveNum = 0;
      return;
    }
    if (((DialogConfigure.curentPage == 0) && (this.dropPosition == 0)) || ((DialogConfigure.curentPage == 0) && (this.dropPosition == 1)))
      this.dropPosition = this.dragPosition;
    this.moveNum = 0;
    ViewGroup localViewGroup = (ViewGroup)getChildAt(this.dropPosition - getFirstVisiblePosition());
    final DialogDateAdapter localDialogDateAdapter = (DialogDateAdapter)getAdapter();
    int j = -(this.dropPosition % this.numColumns - this.dragPosition % this.numColumns);
    int k = -(this.dropPosition / this.numColumns - this.dragPosition / this.numColumns);
    this.AtoB = getDownAnimation(-j, -k);
    AutoSoftInfo localAutoSoftInfo1 = (AutoSoftInfo)localDialogDateAdapter.getItem(this.dropPosition);
    AutoSoftInfo localAutoSoftInfo2 = (AutoSoftInfo)localDialogDateAdapter.getItem(this.dragPosition);
    PackageManager localPackageManager2;
    if (this.dropPosition != this.dragPosition)
    {
      Logger.i("movexy", "drop:" + this.dropPosition + " drag:" + this.dragPosition + "   x-move:" + j + "    y-move:" + k);
      if (localAutoSoftInfo1.getAsIsFolder() != 1)
        break label424;
      localPackageManager2 = getContext().getPackageManager();
    }
    while (true)
    {
      try
      {
        ApplicationInfo localApplicationInfo3 = localPackageManager2.getApplicationInfo(localAutoSoftInfo2.getAspkg(), 8192);
        localAutoSoftInfo1.add(new ShortcutInfo(localPackageManager2.getActivityIcon(new ComponentName(localAutoSoftInfo2.getAspkg(), localAutoSoftInfo2.getActivityName())), localApplicationInfo3.packageName, localApplicationInfo3.className));
        ShowShortcutUtils.updateFolderIcon(getResources(), localAutoSoftInfo1);
        this.fromView.startAnimation(this.AtoB);
        this.AtoB.setAnimationListener(new Animation.AnimationListener()
        {
          public void onAnimationEnd(Animation paramAnonymousAnimation)
          {
            localDialogDateAdapter.exchange(DialogDragGrid.this.dragPosition, DialogDragGrid.this.dropPosition);
            localDialogDateAdapter.notifyDataSetChanged();
          }

          public void onAnimationRepeat(Animation paramAnonymousAnimation)
          {
          }

          public void onAnimationStart(Animation paramAnonymousAnimation)
          {
          }
        });
        return;
      }
      catch (PackageManager.NameNotFoundException localNameNotFoundException2)
      {
        localNameNotFoundException2.printStackTrace();
        continue;
      }
      label424: if ((localAutoSoftInfo1.getAsIsFolder() == 0) && (localAutoSoftInfo2.getAsIsFolder() == 0) && (localAutoSoftInfo1.getAsParentid() == 0))
      {
        PackageManager localPackageManager1 = getContext().getPackageManager();
        try
        {
          ApplicationInfo localApplicationInfo1 = localPackageManager1.getApplicationInfo(localAutoSoftInfo1.getAspkg(), 8192);
          ApplicationInfo localApplicationInfo2 = localPackageManager1.getApplicationInfo(localAutoSoftInfo2.getAspkg(), 8192);
          localAutoSoftInfo1.add(new ShortcutInfo(localApplicationInfo1.loadIcon(localPackageManager1), localApplicationInfo1.packageName, localApplicationInfo1.className));
          localAutoSoftInfo1.add(new ShortcutInfo(localApplicationInfo2.loadIcon(localPackageManager1), localApplicationInfo2.packageName, localApplicationInfo2.className));
          ShowShortcutUtils.updateFolderIcon(getResources(), localAutoSoftInfo1);
        }
        catch (PackageManager.NameNotFoundException localNameNotFoundException1)
        {
          localNameNotFoundException1.printStackTrace();
        }
      }
      else
      {
        localViewGroup.startAnimation(getMyAnimation(j, k));
      }
    }
  }

  private void startDrag(final Bitmap paramBitmap, int paramInt1, int paramInt2)
  {
    this.windowManager = ((WindowManager)getContext().getSystemService("window"));
    Animation localAnimation = AnimationUtils.loadAnimation(getContext(), 2130968583);
    localAnimation.setAnimationListener(new Animation.AnimationListener()
    {
      public void onAnimationEnd(Animation paramAnonymousAnimation)
      {
        DialogDragGrid.this.fromView.setVisibility(8);
        DialogDragGrid.this.stopDrag();
        DialogDragGrid.this.windowParams = new WindowManager.LayoutParams();
        DialogDragGrid.this.windowParams.gravity = 51;
        DialogDragGrid.this.windowParams.x = DialogDragGrid.this.fromView.getLeft();
        DialogDragGrid.this.windowParams.y = (DialogDragGrid.this.fromView.getTop() + (int)(40.0F * DialogConfigure.screenDensity));
        DialogDragGrid.this.windowParams.alpha = 0.8F;
        DialogDragGrid.this.windowParams.height = -2;
        DialogDragGrid.this.windowParams.width = -2;
        DialogDragGrid.this.iv_drag = new ImageView(DialogDragGrid.this.getContext());
        DialogDragGrid.this.iv_drag.setImageBitmap(paramBitmap);
        DialogDragGrid.this.windowManager.addView(DialogDragGrid.this.iv_drag, DialogDragGrid.this.windowParams);
        DialogDragGrid.this.iv_drag.startAnimation(AnimationUtils.loadAnimation(DialogDragGrid.this.getContext(), 2130968577));
      }

      public void onAnimationRepeat(Animation paramAnonymousAnimation)
      {
      }

      public void onAnimationStart(Animation paramAnonymousAnimation)
      {
      }
    });
    this.fromView.startAnimation(localAnimation);
  }

  private void stopDrag()
  {
    if (this.iv_drag != null)
    {
      this.windowManager.removeView(this.iv_drag);
      this.iv_drag = null;
    }
  }

  public Animation getDelAnimation(int paramInt1, int paramInt2)
  {
    AnimationSet localAnimationSet = new AnimationSet(true);
    RotateAnimation localRotateAnimation = new RotateAnimation(0.0F, 360.0F, 1, 0.5F, 1, 0.5F);
    localRotateAnimation.setFillAfter(true);
    localRotateAnimation.setDuration(550L);
    AlphaAnimation localAlphaAnimation = new AlphaAnimation(1.0F, 0.0F);
    localAlphaAnimation.setFillAfter(true);
    localAlphaAnimation.setDuration(550L);
    localAnimationSet.addAnimation(localAlphaAnimation);
    localAnimationSet.addAnimation(localRotateAnimation);
    return localAnimationSet;
  }

  public Animation getDownAnimation(float paramFloat1, float paramFloat2)
  {
    AnimationSet localAnimationSet = new AnimationSet(true);
    TranslateAnimation localTranslateAnimation = new TranslateAnimation(1, paramFloat1, 1, paramFloat1, 1, paramFloat2, 1, paramFloat2);
    localTranslateAnimation.setFillAfter(true);
    localTranslateAnimation.setDuration(550L);
    AlphaAnimation localAlphaAnimation = new AlphaAnimation(0.1F, 1.0F);
    localAlphaAnimation.setFillAfter(true);
    localAlphaAnimation.setDuration(550L);
    ScaleAnimation localScaleAnimation = new ScaleAnimation(1.2F, 1.0F, 1.2F, 1.0F);
    localScaleAnimation.setFillAfter(true);
    localScaleAnimation.setDuration(550L);
    localAnimationSet.addAnimation(localTranslateAnimation);
    localAnimationSet.addAnimation(localAlphaAnimation);
    localAnimationSet.addAnimation(localScaleAnimation);
    return localAnimationSet;
  }

  public Animation getMyAnimation(float paramFloat1, float paramFloat2)
  {
    TranslateAnimation localTranslateAnimation = new TranslateAnimation(1, 0.0F, 1, paramFloat1, 1, 0.0F, 1, paramFloat2);
    localTranslateAnimation.setFillAfter(true);
    localTranslateAnimation.setDuration(550L);
    return localTranslateAnimation;
  }

  public boolean onInterceptTouchEvent(MotionEvent paramMotionEvent)
  {
    if (paramMotionEvent.getAction() == 0)
      return setOnItemLongClickListener(paramMotionEvent);
    return super.onInterceptTouchEvent(paramMotionEvent);
  }

  public boolean onTouchEvent(MotionEvent paramMotionEvent)
  {
    int i;
    int j;
    if ((this.iv_drag != null) && (this.dragPosition != -1))
    {
      i = (int)paramMotionEvent.getX();
      j = (int)paramMotionEvent.getY();
      switch (paramMotionEvent.getAction())
      {
      default:
      case 2:
      case 1:
      }
    }
    while (true)
    {
      return super.onTouchEvent(paramMotionEvent);
      if (!this.isCountXY)
      {
        this.xtox = (i - this.mLastX);
        this.ytoy = (j - this.mLastY);
        this.isCountXY = true;
      }
      Logger.i("draggrid", "x:" + i);
      onDrag(i, j);
      continue;
      stopDrag();
      onDrop(i, j);
    }
  }

  public void setLongFlag(boolean paramBoolean)
  {
    this.flag = paramBoolean;
  }

  public void setOnItemChangeListener(G_ItemChangeListener paramG_ItemChangeListener)
  {
    this.itemListener = paramG_ItemChangeListener;
  }

  public boolean setOnItemLongClickListener(final MotionEvent paramMotionEvent)
  {
    setOnItemLongClickListener(new AdapterView.OnItemLongClickListener()
    {
      public boolean onItemLongClick(AdapterView<?> paramAnonymousAdapterView, View paramAnonymousView, int paramAnonymousInt, long paramAnonymousLong)
      {
        DialogConfigure.isMove = true;
        int i = (int)paramMotionEvent.getX();
        int j = (int)paramMotionEvent.getY();
        DialogDragGrid.this.mLastX = i;
        DialogDragGrid.this.mLastY = j;
        DialogDragGrid localDialogDragGrid = DialogDragGrid.this;
        DialogDragGrid.this.dropPosition = paramAnonymousInt;
        localDialogDragGrid.dragPosition = paramAnonymousInt;
        if ((DialogDragGrid.this.dragPosition == -1) || (DialogDragGrid.this.parentid == 0))
          return true;
        DialogDragGrid.this.fromView = ((ViewGroup)DialogDragGrid.this.getChildAt(DialogDragGrid.this.dragPosition - DialogDragGrid.this.getFirstVisiblePosition()));
        DialogDragGrid.this.fromView.destroyDrawingCache();
        DialogDragGrid.this.fromView.setDrawingCacheEnabled(true);
        DialogDragGrid.this.fromView.setDrawingCacheBackgroundColor(-9586707);
        Bitmap localBitmap1 = Bitmap.createBitmap(DialogDragGrid.this.fromView.getDrawingCache());
        Bitmap localBitmap2 = Bitmap.createBitmap(localBitmap1, 8, 8, -16 + localBitmap1.getWidth(), -8 + localBitmap1.getHeight());
        DialogDragGrid.this.startDrag(localBitmap2, i, j);
        return true;
      }
    });
    return super.onInterceptTouchEvent(paramMotionEvent);
  }

  public void setPageListener(G_PageListener paramG_PageListener)
  {
    this.pageListener = paramG_PageListener;
  }

  public static abstract interface G_ItemChangeListener
  {
    public abstract void change(int paramInt1, int paramInt2, int paramInt3);
  }

  public static abstract interface G_PageListener
  {
    public abstract void page(int paramInt1, int paramInt2);
  }
}

/* Location:           C:\Documents and Settings\Administrator\classes_dex2jar.jar
 * Qualified Name:     com.appwoo.txtws.util.DialogDragGrid
 * JD-Core Version:    0.6.2
 */